package com.wego.service.impl;

import com.github.pagehelper.Page;
import com.wego.common.base.impl.BaseServiceImpl;
import com.wego.common.bean.PageBean;
import com.wego.entity.domain.User;
import com.wego.entity.query.UserQuery;
import com.wego.mapper.UserMapper;
import com.wego.service.UserService;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;

@Service
public class UserServiceImpl extends BaseServiceImpl<User> implements UserService {

    @Autowired
    private UserMapper userMapper;

    @Override
    public PageBean<User> selectPage(UserQuery userQuery) {
        //设置分页信息
        Page<User> page = userQuery.toPage();
        //查询数据
        userMapper.selectList(userQuery);
        //将MyBatis提供的Page对象转换成我们自己的PageBean对象
        return new PageBean<>(page);
    }

    @Override
    public int selectCount(User user) {
        return userMapper.selectCount(user);
    }

    @Override
    public boolean isExistUser(User user) {
        int count = userMapper.selectCount(user);
        if (count == 0)
            return false;
        else
            return true;
    }

    @Override
    public User selectOne(User user){
        User user1 = userMapper.selectOne(user);
        return user1;
    }
}
